<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同名称" prop="contractName">
        <el-input
          v-model="queryParams.contractName"
          placeholder="请输入合同名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['web:PaymentContractInformation:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['web:PaymentContractInformation:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['web:PaymentContractInformation:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['web:PaymentContractInformation:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
          <el-button
            type="info"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"
          >导入</el-button>
        </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="PaymentContractInformationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column label="合同名称" align="center" prop="contractName" />
      <el-table-column label="项目经办人" align="center" prop="projectManager" />
      <el-table-column label="合同签订部门" align="center" prop="contractDepartment" />
      <el-table-column label="合同签订情况" align="center" prop="contractSignStatus" />
      <el-table-column label="合同执行情况" align="center" prop="contractExecutiveStatus" />
      <el-table-column label="发票总额" align="center" prop="invoiceTotalAmount" />
      <el-table-column label="发票时间1" align="center" prop="invoiceTimeOne" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.invoiceTimeOne, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发票号1" align="center" prop="invoiceNumberOne" />
      <el-table-column label="发票金额1" align="center" prop="invoiceMoneyOne" />
      <el-table-column label="经办人1" align="center" prop="invoiceAgentOne" />
      <el-table-column label="付款总额" align="center" prop="totalAmount" />
      <el-table-column label="付款时间1" align="center" prop="paymentTimeOne" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.paymentTimeOne, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="付款金额1" align="center" prop="paymentAmountOne" />
      <el-table-column label="录入情况" align="center" prop="inputCondition" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['web:PaymentContractInformation:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['web:PaymentContractInformation:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
 

    
    <!-- 添加或修改付款合同对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="合同编号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model="form.contractName" placeholder="请输入合同名称" />
        </el-form-item>
        <el-form-item label="项目经办人" prop="projectManager">
          <el-input v-model="form.projectManager" placeholder="请输入项目经办人" />
        </el-form-item>
        <el-form-item label="合同签订部门" prop="contractDepartment">
          <el-input v-model="form.contractDepartment" placeholder="请输入合同签订部门" />
        </el-form-item>
        <el-form-item label="合同签订情况" prop="contractSignStatus">
          <el-input v-model="form.contractSignStatus" placeholder="请输入合同签订情况" />
        </el-form-item>
        <el-form-item label="合同执行情况" prop="contractExecutiveStatus">
          <el-input v-model="form.contractExecutiveStatus" placeholder="请输入同执行情况" />
        </el-form-item>
        <el-form-item label="发票总额" prop="invoiceTotalAmount">
          <el-input v-model="form.invoiceTotalAmount" placeholder="请输入发票总额" />
        </el-form-item>
        <el-form-item label="发票时间1" prop="invoiceTimeOne">
          <el-date-picker clearable
            v-model="form.invoiceTimeOne"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发票时间1">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发票号1" prop="invoiceNumberOne">
          <el-input v-model="form.invoiceNumberOne" placeholder="请输入发票号1" />
        </el-form-item>
        <el-form-item label="发票金额1" prop="invoiceMoneyOne">
          <el-input v-model="form.invoiceMoneyOne" placeholder="请输入发票金额1" />
        </el-form-item>
        <el-form-item label="经办人1" prop="invoiceAgentOne">
          <el-input v-model="form.invoiceAgentOne" placeholder="请输入经办人1" />
        </el-form-item>
        <el-form-item label="付款总额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入付款总额" />
        </el-form-item>
        <el-form-item label="付款时间1" prop="paymentTimeOne">
          <el-date-picker clearable
            v-model="form.paymentTimeOne"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择付款时间1">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="付款金额1" prop="paymentAmountOne">
          <el-input v-model="form.paymentAmountOne" placeholder="请输入付款金额1" />
        </el-form-item>
        <el-form-item label="录入情况" prop="inputCondition">
          <el-input v-model="form.inputCondition" placeholder="请输入录入情况" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入弹窗-->
  <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
    <el-upload
      ref="upload"
      :limit="1"
      accept=".xlsx, .xls"
      :headers="upload.headers"
      :action="upload.url"
      :disabled="upload.isUploading"
      :on-progress="handleFileUploadProgress"
      :on-success="handleFileSuccess"
      :auto-upload="false"
      drag
    >
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip text-center" slot="tip">
        <span>仅允许导入xls、xlsx格式文件。</span>
        <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
      </div>
    </el-upload>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFileForm">确 定</el-button>
      <el-button @click="upload.open = false">取 消</el-button>
    </div>
  </el-dialog>

  </div>
</template>

<script>
import { listPaymentContractInformation, getPaymentContractInformation, delPaymentContractInformation, addPaymentContractInformation, updatePaymentContractInformation } from "@/api/web/PaymentContractInformation";
import { getToken } from "@/utils/auth";
export default {
  name: "PaymentContractInformation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 付款合同表格数据
      PaymentContractInformationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      upload: {
            // 是否显示弹出层（用户导入）
            open: false,
            // 弹出层标题（用户导入）
            title: "",
            // 是否禁用上传
            isUploading: false,
            // 是否更新已经存在的用户数据
            updateSupport: 0,
            // 设置上传的请求头部
            headers: { Authorization: "Bearer " + getToken() },
            // 上传的地址
            url: process.env.VUE_APP_BASE_API + "web/PaymentContractInformation/importData"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询付款合同列表 */
    getList() {
      this.loading = true;
      listPaymentContractInformation(this.queryParams).then(response => {
        this.PaymentContractInformationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractNo: null,
        contractName: null,
        projectManager: null,
        contractDepartment: null,
        contractSignStatus: null,
        contractExecutiveStatus: null,
        invoiceTotalAmount: null,
        invoiceTimeOne: null,
        invoiceNumberOne: null,
        invoiceMoneyOne: null,
        invoiceAgentOne: null,
        totalAmount: null,
        paymentTimeOne: null,
        paymentAmountOne: null,
        inputCondition: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
     /** 导入按钮操作 */
  handleImport() {
    this.upload.title = "商机导入";
    this.upload.open = true;
  },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加付款合同";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPaymentContractInformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改付款合同";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePaymentContractInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPaymentContractInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除付款合同编号为"' + ids + '"的数据项？').then(function() {
        return delPaymentContractInformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 下载模板操作 */
    importTemplate() {
    this.download('/web/PaymentContractInformation/importTemplate', {
    }, `付款合同导入模板.xlsx`)
  },
    /** 导出按钮操作 */
    handleExport() {
      this.download('web/PaymentContractInformation/export', {
        ...this.queryParams
      }, `PaymentContractInformation_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>



